import 'package:enterprise_v6_app/app/components/custom_modele/custom_dropdown_selection.dart';
import 'package:enterprise_v6_app/app/components/custom_modele/custom_search_enter.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/entities/application/smart_warehouse/product_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/smart_warehouse/product_management/product_management_controller.dart';

/// 产品管理页面
class ProductManagementPage extends StatelessWidget {
  ProductManagementPage({super.key});

  final controller = Get.put(ProductManagementController());

  //获取条件搜索项
  Widget _getSearchConditionWidget() {
    return Column(
      children: [
        CustomSearchEnter(
          hintText: '搜索产品名称',
          text: controller.search,
          onCallBack: (value) {
            controller.search = value;
            controller.refreshPage();
          },
        ),
        AppGaps.vGap8,
        Row(
          children: [
            Expanded(
                child: CustomDropdownSelection(
              text: controller.warehouse.getShowName(),
              hintText: '选择所在仓库',
              onCallBack: controller.showWarehouseSelection,
            )),
            AppGaps.hGap10,
            Expanded(
                child: CustomDropdownSelection(
              text: controller.inventoryEntity.getShowName(),
              hintText: '选择库存情况',
              onCallBack: controller.showInventorySelection,
            )),
          ],
        ),

        // _getFilter()
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Container(
            padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 14.w),
            alignment: Alignment.topCenter,
            color: const Color(0xffF5F5F6),
            child: Column(
              children: [
                _getSearchConditionWidget(),
                AppGaps.vGap14,
                Expanded(
                  child: CustomEasyRefreshList<ProductEntity>(
                    key: controller.globalKey,
                    dataLoad: (pageIndex, pageSize, {String? search}) async {
                      return controller.getProductListData(pageIndex, pageSize);
                    },
                    itemBuilder: (ProductEntity item, int index) {
                      return Container(
                        padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 15.w),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10.w)),
                        ),
                        child: Row(
                          children: [
                            Container(
                              color: const Color(0xff5C6DFF),
                              width: 6.w,
                              height: 6.w,
                            ),
                            AppGaps.hGap8,
                            Expanded(
                                child: Text(
                              item.name!,
                              style: TextStyle(
                                fontSize: 14.sp,
                                fontWeight: FontWeight.w500,
                                color: const Color(0xff4D4D4D),
                              ),
                            )),
                            SvgPicture.asset(
                              AppImages.icon_product,
                              width: 30.w,
                              height: 30.w,
                              // colorFilter: const ColorFilter.mode(Colors.white, BlendMode.srcIn),
                            ),
                            Text(
                              '${item.inventory}',
                              style: TextStyle(
                                fontSize: 16.sp,
                                fontWeight: FontWeight.w500,
                                color: const Color(0xff495061),
                              ),
                            ),
                            Text(
                              '件',
                              style: TextStyle(
                                fontSize: 12.sp,
                                fontWeight: FontWeight.w500,
                                color: const Color(0xff495061),
                              ),
                            )
                          ],
                        ),
                      ).clickOnce(() {
                        controller.toDetailsPage(item.id!);
                      });
                    },
                  ),
                ),
              ],
            ),
          );
        });
  }
}
